﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace EmailReporting.Data
{
    public class Invoice
    {
        // Author: Otto Neff | webapps-in-action.com 
        public string InvoiceCustomer { get; set; }
        public string InvoiceCustomerID { get { return Guid.NewGuid().ToString(); } }
        public DateTime InvoiceDate { get; set; }
        public List<InvoicePos> InvoicePositions { get; set; }
        public int TotalItems
        {
            get
            {
                if (this.InvoicePositions == null)
                {
                    return 0;
                }
                int itemCount = 0;
                foreach (InvoicePos p in this.InvoicePositions)
                {
                    itemCount = itemCount + p.Amount;
                }
                return itemCount;
            }
        }
        public decimal TotalSum
        {
            get
            {
                if (this.InvoicePositions == null)
                {
                    return 0;
                }
                decimal sum = 0;
                foreach (InvoicePos p in this.InvoicePositions)
                {
                    sum = sum + (p.Amount * p.UnitPrice);
                }
                return sum;
            }
        }
    }
}
